<?php

use app\models\KeyMap;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/**
 * @var $this yii\web\View
 * @var $publish app\models\AgentPublish
 */

$this->title = '添加/修改信息';
$this->params['breadcrumbs'][] = '宣传管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $form = ActiveForm::begin(['id' => 'AgentPublishEditForm', 'options' => ['enctype' => 'multipart/form-data']]);?>
<?php echo Html::activeHiddenInput($publish, 'id');?>
<?php echo $form->field($publish, 'name');?>
<?php echo $form->field($publish, 'type')->radioList(KeyMap::getValues('agent_publish_type'));?>
<?php echo $form->field($publish, 'value')->hiddenInput();?>
<div class="form-group">
    <div class="col-lg-offset-1 col-lg-11">
        <button type="button" class="btn btn-default" onclick="window.history.go(-1);"><i class="ace-icon fa fa-arrow-left bigger-110"></i>返回</button>
        <button class="btn btn-primary"><i class="ace-icon fa fa-check bigger-110"></i>保存</button>
        <button type="reset" class="btn btn-warning"><i class="ace-icon fa fa-undo bigger-110"></i>重置</button>
    </div>
</div>
<?php $form->end();?>
<script>
    function pageInit() {
        $('[name="AgentPublish[type]"]').click(function () {
            var $input = $('[name="AgentPublish[value]"]');
            var oldValue = $input.val();
            var type = parseInt($(this).val());
            switch (type) {
                case 1: // 单行文本
                    $input.replaceWith('<input type="text" name="AgentPublish[value]" class="form-control" />');
                    break;
                case 2: // 多行文本
                    $input.replaceWith('<textarea type="text" name="AgentPublish[value]" class="form-control" rows="8"></textarea>');
                    break;
                case 3: // 富文本
                    break;
                case 4: // 文件
                    $input.replaceWith('<input type="file" name="AgentPublish[value]" />');
                    break;
                case 5: // 图片
                    $input.replaceWith('<input type="file" name="AgentPublish[value]" />');
                    break;
            }
            $('[name="AgentPublish[value]"]').val(oldValue);
        });
        $('[name="AgentPublish[type]"]:checked').click();
    }
</script>
